define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    require('oa/js/schedule/scheduleContentCtrl');
    var scheduleUtil = require('oa/js/schedule/asset/utils/scheduleUtil');

    var contentId = 'scheduleContent';

    var eventTypes = [];

    var scheduleService = {
        currentView: null,
        //用户自定义的事件列表
        setTypes: function(etypes) {
            eventTypes = etypes;
        },
        calendarIsOpen: function(){
            return $('#' + contentId).is(':visible');
        },
        showFullcalendar: function(view, start) {
            var me = this;
            me.currentView = view;

            var viewName = scheduleUtil.getViewName(view);

            //仅仅显示隐藏，永不销毁
            if($('#' + contentId).size() == 0){
                rk.oa.popupContent({
                    id: contentId,
                    size: 'middle',
                    onCloseClick: function(){
                        rk.oa.hideContent(contentId);
                    },
                    onSuccess: function(elemSelector){
                        $(elemSelector).scheduleContentCtrl({
                            view: viewName,
                            start: start
                        });
                        me._handleCalendarDisplay(view, start);
                        scheduleUtil.loadEvents();
                    }
                });
            }else{
                rk.oa.showContent(contentId);
                me._handleCalendarDisplay(view, start);
            }

        },
        _handleCalendarDisplay: function(view, start){
            var me = this;
            var calendar = $('#calendar');
            var viewName = scheduleUtil.getViewName(view);
            var calendarViewName = calendar.fullCalendar( 'getView' ).name;
            calendar.data('do-no-refresh-panel', 'true');
            if(calendarViewName != viewName){
                calendar.fullCalendar( 'changeView', viewName );
            }else{
                calendar.fullCalendar( 'gotoDate', start );
            }
        }
    };
    
    module.exports = scheduleService;
});
